/*
 * @Author: xyf
 * @Date: 2021-06-28 18:06:59
 * @LastEditTime: 2021-06-28 18:07:12
 * @LastEditors: xyf
 * @Description: Storage二次封装
 */
import config from '@/config'

export default {
  setItem(key, val) {
    let storage = this.getStroage()
    storage[key] = val
    window.localStorage.setItem(config.namespace, JSON.stringify(storage))
  },

  getItem(key) {
    return this.getStroage()[key]
  },

  getStroage() {
    return JSON.parse(window.localStorage.getItem(config.namespace) || '{}')
  },

  clearItem(key) {
    let storage = this.getStroage()
    delete storage[key]
    window.localStorage.setItem(config.namespace, JSON.stringify(storage))
  },

  clearAll() {
    window.localStorage.clear()
  }
}
